﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Innova.Entites;
using Innova.BusinessLogic;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.Configuration;

namespace Innova.Movil.Controllers
{
    public class ReservaController : Controller
    {
        public ReservaController()
        {
        }

        [Dependency]
        public IServicioBL servicioBL { get; set; }

        [Dependency]
        public IReservaBL reservaBL { get; set; }

        public ActionResult Create(Int32 idServicio)
        {
            var servicio = servicioBL.GetFromServicioById(idServicio);
            ViewData["PatrocinadorId"] = servicio.PatrocinadorId;
            ViewData["ServicioId"] = idServicio;
            return View();
        }

        [HttpPost]
        public ActionResult Create(FormCollection colection, RESERVA reserva)
        {
            var newReserva = new RESERVA();

            try{
                
                newReserva.CantidadAdultos = reserva.CantidadAdultos;
                newReserva.CantidadNiños = reserva.CantidadNiños;
                newReserva.Dias = reserva.Dias;
                newReserva.FechaLlegada = reserva.FechaLlegada;
                newReserva.FechaSalida = reserva.FechaSalida;
                newReserva.ServicioId = reserva.ServicioId;
                newReserva.Tarifa = reserva.Tarifa;
                newReserva.Monto = reserva.Tarifa * reserva.Dias;

                reservaBL.AddReserva(newReserva);   

                var msg = "Rservacion Correcta";
                TempData["AlertMessage"] = msg;

                return RedirectToAction("Create", new { idServicio = reserva.ServicioId });
            }
            catch (Exception ex)
            {
                var msg = ex.Message;
                msg = "Verifique los datos de la reserva";

                TempData["AlertMessage"] = msg;

                return RedirectToAction("Create", new { idServicio = reserva.ServicioId });
            }
        }


    }
}
